package io;

import java.io.FileInputStream;
import java.io.IOException;

public class demo4 {
	public static void main(String[] args) throws IOException {
		// 创建一个FileInputStream对象,构造方法中绑定要读取的数据源
		FileInputStream fis = new FileInputStream("E:\\javacode\\111\\src\\io\\b.txt");
		// 调用FileOutputStream对象中read方法，读取文件
		/*
		 * byte[] bytes = new byte[2]; int len = fis.read(bytes);
		 * System.out.println(len);//2 读取的有效字节个数
		 * System.out.println(Arrays.toString(bytes));// [97, 66] System.out.println(new
		 * String(bytes));// aB
		 * 
		 * len = fis.read(bytes); System.out.println(len);//2 读取的有效字节个数
		 * System.out.println(Arrays.toString(bytes));// [99, 100]
		 * System.out.println(new String(bytes));// cd
		 * 
		 * len = fis.read(bytes); System.out.println(len);// -1 读取结束标志
		 * System.out.println(Arrays.toString(bytes));// [99, 100]
		 * System.out.println(new String(bytes));// cd fis.close();
		 */
		
		
		byte[] bytes =new byte[1024];
		int len=0;
		while ((len=fis.read(bytes))!=-1) {
			System.out.println(new String(bytes,0,len));//有效字符串转换，不浪费内存空间
		}
		fis.close();
	}
}
